package com.wangjiacai.hql.condition.where;

import com.wangjiacai.hql.condition.Condition;
import com.wangjiacai.util.HqlUtil;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;

@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Condition(condition = In.InCondition.class,column = In.InCondition.class)
public @interface In {

    String column() default "";

    String hql() default "";

    class InCondition implements Condition.Where<In,List>, Condition.Column<In> {
        @Override
        public String where(In in,String property,String column,Object obj,List value) {
            return in.hql().equals("")?column+" in(:"+property+")":column+" in ("+ HqlUtil.parseHql(in.hql(),obj)+")";
        }

        @Override
        public String column(In in, String property) {
            return in.column().equals("")?property:in.column();
        }
    }

}
